﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
   public class DichVuDAO
    {
       public List<DichVuDTO> DanhSachDichVu()
       {
           List<DichVuDTO> kq = new List<DichVuDTO>();

           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "select*from DichVu";
           SqlDataReader dr = dp.ExecuteQuery(strsql);
           if (dr.HasRows)
           {
               while (dr.Read())
               {
                   DichVuDTO dv = new DichVuDTO();
                   dv.DV_ID = int.Parse(dr["DV_ID"].ToString());
                   dv.DonGia = float.Parse(dr["DonGia"].ToString());
                   dv.MaDichVu = dr["MaDichVu"].ToString();
                   dv.NDV_ID = int.Parse(dr["NDV_ID"].ToString());
                   dv.TenDichVu = dr["TenDichVu"].ToString();
                   kq.Add(dv);

               }
           }           
           return kq;
       }
       public Boolean ThemDichVu(DichVuDTO dv)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "insert into DichVu(MaDichVu,TenDichVu,DonGia,NDV_ID)";
           strsql += " values('" + dv.MaDichVu + "','" + dv.TenDichVu + "'," + dv.DonGia + "," + dv.NDV_ID + ")";
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean XoaDichVuByID(int dV_ID)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "delete from DichVu where DV_ID="+dV_ID;
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean XoaDichVuByMaDichVu(string maDichVu)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "delete from DichVu where MaDichVu='" + maDichVu + "'"; ;
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean CapNhatDichVu(DichVuDTO dv)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "update DichVu set MaDichVu='" + dv.MaDichVu + "' and TenDichVu='" + dv.TenDichVu + "' and DonGia=" + dv.DonGia + " and NDV_ID=" + dv.NDV_ID + " where DV_ID=" + dv.DV_ID;
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
    }
}
